package com.health.system.service.system.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import cn.org.rapid_framework.page.Page;
import cn.org.rapid_framework.page.PageRequest;

import com.health.system.dao.system.RoleDao;
import com.health.system.javacommon.base.BaseManager;
import com.health.system.javacommon.base.EntityDao;
import com.health.system.model.system.Role;
import com.health.system.service.system.RoleManager;
import com.health.system.service.system.UserManager;
import com.health.system.springSecurity.UserInfo;
import com.health.system.springSecurity.LogonUser;

/**
* <p>Title: 角色 业务处理层 </p>
* <p>Description: spring事务实现层,调用Dao层取数据.健康通 </p>
* Copyright: Copyright (c) 2011-03 
* Company: 
* 
* @author 鲍忠启 
* @version 1.0 
*/

@Component("roleManager")
@Transactional
public class RoleManagerImpl extends BaseManager<Role,java.lang.String> 
					implements RoleManager {

	private RoleDao roleDao;
	private UserManager userManager;
	
	

	/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性*/
	public void setRoleDao(RoleDao dao) {
		this.roleDao = dao;
	}
	public EntityDao getEntityDao() {
		return this.roleDao;
	}
	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}
	
	
	@Transactional(readOnly=true)
	public Page findByPageRequest(PageRequest pr) {
		return roleDao.findByPageRequest(pr);
	}
	
	public List getRoleList(Role role) {
		return roleDao.getRoleList(role);
	}
	public List selectList(){
		return roleDao.selectList();
	}
	public List getListByMap(Map map){
		return roleDao.getListByMap(map);
	}
	
	public Boolean  removeByIdArry(Role u) {
		Boolean result =false;
		int i =-1,size=u.getIdList().size();
		i =roleDao.removeByIdArry(u);
		if(i==size){
			result =true;
		}else{
			throw new RuntimeException();
		}
		return result;
	}
	/**
	* <p>查询所有节点树</p>
	* <p>以树形结构查询所有节点</p>
	* @param Role u
	* @author bzq
	* @return List<Role>
	*/
	@Transactional(readOnly=true)
	public List getAllTree(){
		return roleDao.getAllTree();
	}
	
	/**
	 * <p>查询当前节点的所有上级节点</p>
	 * <p>以树形结构查询</p>
	 * @param Role u
	 * @author bzq
	 * @return List<Role>
	*/
	@Transactional(readOnly=true)
	public List getParentTree(Role role){
		return roleDao.getParentTree(role);
	}
	
	/**
	 * <p>查询当前节点的所有下级节点</p>
	 * <p>以树形结构查询</p>
	 * @param Role u
	 * @author bzq
	 * @return List<Role>
	*/
	@Transactional(readOnly=true)
	public List getSubsetTree(Role role){
		return roleDao.getSubsetTree(role);
	}
	/**
	 * <p>按当前操作员,查询它角色节点的所有下级节点</p>
	 * <p>以树形结构查询</p>
	 * @param Map map
	 * @author bzq
	 * @return List<Role>
	*/	
	@Transactional(readOnly=true)
	public List getTree(Map map){
		//从登录用户类中取当前用户信息
		UserInfo userInfo = LogonUser.logonUser();
		String userId = userInfo.getUserId();
		String maxRoleId =  userManager.getUserMaxRoleId(userId);
		
		Role role = new Role();
		role.setId(maxRoleId);
		List role_list = this.getSubsetTree(role);
		return role_list;
	}
}
